package com.ruyuan.eshop.common.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruyuan.eshop.common.domain.vo.PriceDetailVO;
import com.ruyuan.eshop.common.enums.TradeStatusEnum;
import com.ruyuan.eshop.common.domain.vo.ConsigneeVO;
import com.ruyuan.eshop.common.domain.vo.TradeVO;
import com.ruyuan.eshop.framework.domain.entity.BaseEntity;
import lombok.Data;

/**
 * 交易表实体
 * @author pwd
 * @version 1.0
 */
@TableName("es_trade")
@Data
public class TradeDO extends BaseEntity {

    private static final long serialVersionUID = 8834971381961212L;

    /**trade_id*/
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    /**交易编号*/
    private String tradeSn;

    /**买家id*/
    private Long memberId;

    /**买家用户名*/
    private String memberName;

    /**支付方式id*/
    private Long paymentMethodId;

    /**支付插件id*/
    private String paymentPluginId;

    /**支付方式名称*/
    private String paymentMethodName;

    /**支付方式类型*/
    private String paymentType;

    /**总价格*/
    private Double totalPrice;

    /**商品价格*/
    private Double goodsPrice;

    /**运费*/
    private Double freightPrice;

    /**优惠的金额*/
    private Double discountPrice;

    /**收货人id*/
    private Long consigneeId;

    /**收货人姓名*/
    private String consigneeName;

    /**收货国家*/
    private String consigneeCountry;

    /**收货国家id*/
    private Long consigneeCountryId;

    /**收货省*/
    private String consigneeProvince;

    /**收货省id*/
    private Long consigneeProvinceId;

    /**收货市*/
    private String consigneeCity;

    /**收货市id*/
    private Long consigneeCityId;

    /**收货区*/
    private String consigneeCounty;

    /**收货区id*/
    private Long consigneeCountyId;

    /**收货镇*/
    private String consigneeTown;

    /**收货镇id*/
    private Long consigneeTownId;

    /**收货详细地址*/
    private String consigneeAddress;

    /**收货人手机号*/
    private String consigneeMobile;

    /**收货人电话*/
    private String consigneeTelephone;

    /**订单json */
    private String orderJson;

    /**订单状态*/
    private String tradeStatus;

    /**
     * 预存款抵扣金额
     */
    @TableField(value = "balance")
    private Double balance;

    public TradeDO() {

    }

    /**
     * 参数构造器
     * @param tradeVO
     */
    public TradeDO(TradeVO tradeVO) {
        PriceDetailVO priceDetail = tradeVO.getPriceDetail();

        this.setTotalPrice(priceDetail.getTotalPrice());
        this.setGoodsPrice(priceDetail.getGoodsPrice());
        this.setFreightPrice(priceDetail.getFreightPrice());
        this.setDiscountPrice(priceDetail.getDiscountPrice());
        this.setBalance(0D);

        ConsigneeVO consignee =  tradeVO.getConsignee();

        this.setConsigneeName(consignee.getName());
        this.setConsigneeAddress(consignee.getAddress());
        this.setConsigneeId(consignee.getConsigneeId());
        this.setConsigneeMobile(consignee.getMobile());

        this.setConsigneeProvince(consignee.getProvince());
        this.setConsigneeCity(consignee.getCity());
        this.setConsigneeCounty(consignee.getCounty());

        this.setConsigneeProvinceId(consignee.getProvinceId());
        this.setConsigneeCityId(consignee.getCityId());
        this.setConsigneeCountyId(consignee.getCountyId());
        this.setConsigneeTown(consignee.getTown());

        this.setTradeSn(tradeVO.getTradeSn());
        this.setPaymentType(tradeVO.getPaymentType());

        //交易状态
        this.setTradeStatus(TradeStatusEnum.NEW.value());
        this.setMemberId(tradeVO.getMemberId());
        this.setMemberName(tradeVO.getMemberName());
    }

}
